import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import { Observable } from 'rxjs';
import { Eureka } from 'src/app/entity/eureka-manage/eureka';
import { tap } from 'rxjs/operators';

const SERVICE_BASE = `${environment.backendServerBaseAddress}/eureka/manage/register`;

@Injectable({
  providedIn: 'root'
})
export class EurekaRegisterService {

  constructor(private http: HttpClient) { }

  /**
   * 获取所有的Eureka
   */
  public getAllEureka(): Observable<Eureka[]> {
    return this.http.get<Eureka[]>(`${SERVICE_BASE}`);
  }

  public createEureka(eureka: Eureka): Observable<Eureka> {
    return this.http.post<any>(`${SERVICE_BASE}`, eureka, {
      headers: {
        'Content-Type': 'application/json'
      }
    });
  }

  public deleteEureka(eurekaCode: string): Observable<any> {
    return this.http.delete<any>(`${SERVICE_BASE}`, {
      params: {
        code: eurekaCode
      }
    });
  }

}
